nginx_source:
  file.managed:
    - name: /tmp/nginx-1.9.9.tar.gz
    - unless: test -e /tmp/nginx-1.9.9.tar.gz
    - user: root
    - group: root
    - makedirs: True
    - source: salt://nginx/nginx-1.9.9.tar.gz
nginx_extract:
  cmd.run:
    - cwd: /tmp
    - names:
      - tar zxf nginx-1.9.9.tar.gz
    - unless: test -d /tmp/nginx-1.9.9
    - require:
      - file: nginx_source
nginx_user:
  user.present:
    - name: admin
    - createhome: False
    - gid_from_name: True
    - shell: /sbin/nologin
nginx_pkg:
  pkg.installed:
    - pkgs:
      - gcc
      - gcc-c++
      - openssl-devel
      - pcre-devel
      - zlib-devel
      - unzip
nginx_compile:
  cmd.run:
    - cwd: /tmp/nginx-1.9.9
    - names:
      -  ./configure --user=admin --group=admin --prefix=/usr/local/nginx --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --pid-path=/var/run/nginx.pid --with-http_realip_module --with-stream --with-stream_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-http_v2_module
      - make
      - make install
    - require:
      - cmd: nginx_extract
      - pkg: nginx_pkg
    - unless: test -d /usr/local/nginx
create_dir:
  cmd.run:
    - names:
      - mkdir -p /usr/local/nginx/conf/{sites-available,sites-enabled,sites-enabled-stream,sites-available-stream}
      - mkdir -p /var/log/nginx
    - unless: test -d /usr/local/nginx/conf/sites-available/
    - require:
      - cmd: nginx_compile
